﻿<!DOCTYPE HTML>
<html>

<head>
  <meta charset="utf-8">
  <meta name="renderer" content="webkit|ie-comp|ie-stand">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
    content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link href="static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
  <link href="static/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
  <link href="static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css" />
  <link href="lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css" />
  <title>登录</title>
  <style>
    .btn {
      margin: 0px 5px;
      width: 100px;
    }

    .form {
      margin-top: 30px;
    }
  </style>
</head>

<body>
  <div class="header"></div>
  <div class="loginWraper">
    <div id="loginform" class="loginBox">
      <h3 class="myfont">报刊管理系统</h3>
      <form class="form form-horizontal" method="post" id="loginfrom">
        <div class="row cl">
          <label class="form-label col-xs-3"><i class="Hui-iconfont c-white">&#xe60d;</i></label>
          <div class="formControls col-xs-8">
            <input id="" name="" type="text" placeholder="账户" class="input-text size-L" v-model="username"
              id="username">
          </div>
        </div>
        <div class="row cl">
          <label class="form-label col-xs-3"><i class="Hui-iconfont c-white">&#xe60e;</i></label>
          <div class="formControls col-xs-8">
            <input id="" name="" type="password" placeholder="密码" class="input-text size-L" v-model="password"
              id="password">
          </div>
        </div>
        <div class="row cl">
          <div class="formControls col-xs-8 col-xs-offset-3">
            <input name="" @click="logininit" type="submit" class="btn btn-primary radius size-L" value="登录">
            <input name="" @click="register" class="btn btn-default radius size-L" value="注册">
          </div>
        </div>
      </form>
    </div>
  </div>
  <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
  <script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
  <script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script>
  <script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
  <script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.js"></script>
  <script type="text/javascript" src="lib/webuploader/0.1.5/webuploader.min.js"></script>
  <script type="text/javascript" src="lib/ueditor/1.4.3/ueditor.config.js"></script>
  <script type="text/javascript" src="lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
  <script type="text/javascript" src="lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
  <script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
  <script src="lib/layer/2.4/layer.js"></script>
  <script src="lib/vue.js"></script>
  <script>
    var vm = new Vue({
      el: '#loginfrom',
      data: {
        username: '',
        password: ''
      },
      methods: {
        logininit() {
          var _this = this;
          $("#loginfrom").validate({
            rules: {
              username: {
                required: true,
              },
              password: {
                required: true,
              }
            },
            onkeyup: false,
            focusCleanup: true,
            success: "valid",
            submitHandler: function (form) {
              $(form).ajaxSubmit({
                type: "GET",
                url: `http://localhost:8080/usertable?username=${_this.username}&&password=${_this.password}`,
                datatype: 'json',
                success: function (data) {
                  if (data.admin == "1" || data.admin == '2') {
                    sessionStorage.setItem('user', _this.username)
                    sessionStorage.setItem('admin',data.admin)
                    location.href = "index.html"
                  } else if (data.admin == '0') {
                    sessionStorage.setItem('user', _this.username)
                    location.href = "userindex.html"
                  } else {
                    layer.msg('用户名不存在或密码错误', {
                      icon: 2,
                      time: 1600
                    })
                    _this.password = '';
                  }
                },
                error: function () {
                  layer.msg('数据库连接失败', {
                    icon: 3,
                    time: 2000
                  })
                }
              });
            }
          });
        },
        register() {
          location.href = 'member-add.html'
        }
      },
    })
  </script>
</body>

</html>